const express = require('express');
const router = express.Router();
const login = require('./admin/login.js');
const manager = require('./admin/manager.js');
const main = require('./admin/main.js');
const nav = require('./admin/nav.js');
const focus = require('./admin/focus.js');
const articleCate = require('./admin/carticleCate');
const article = require('./admin/article.js');
router.use((req,res,next)=>{  
    const myURL = new URL(req.url,'http://localhost:3000/')
    let pathname = myURL.pathname;
   if(req.session.userinfo&&req.session.userinfo.username){
       next();
   }else{
       if(pathname=='/login'||pathname=='/login/dologin'||pathname=='/login/verify'){
           next();
       }else{
           res.redirect('/admin/login')
       }
   }})
router.get('/',(req,res)=>{
    res.send('后台界面')
    console.log('niaho')
});
router.use('/main',main)
router.use('/manager',manager)
router.use('/login',login)
router.use('/nav',nav)
router.use('/focus',focus)
router.use('/articleCate',articleCate)
router.use('/article',article)

module.exports = router;